#pragma once

#include "common.h"
#include "ntdproto.h"

class TCPClient : public NtdProtoParser
{
public:
	TCPClient();
	virtual ~TCPClient();

	bool Connect(const std::string& ip, int port);
	void Close();

	void OnWrite();
	void OnRead();
	void OnError();
	void OnClose();
	void OnConnected();

	void OnTimer();

	void SetRateLimit(uint32 limit);//Bytes/sec

protected:
	virtual void HandleProtoFeedback(NtdProtoFeedback * proto, void* pContext);

private:
	void SendData(); 

private:

	int32 m_seq;
	event_base * m_base;
	struct bufferevent * m_bev;
	NtdProtoData m_protodata;

	struct event m_timeout;
	int32 m_owd_base;

	uint32 m_ratelimit;
	uint64 m_pktInterval;//us
	uint64 m_lastsent;//us
};